package com.carhome.ui.fagment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import com.carhome.R;
import com.carhome.adapter.ArticleMainAdapter;
import com.shizhefei.view.indicator.IndicatorViewPager;
import com.shizhefei.view.indicator.ScrollIndicatorView;
import com.shizhefei.view.indicator.slidebar.ColorBar;
import com.shizhefei.view.indicator.transition.OnTransitionTextListener;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class ArticleFragment extends Fragment {
	private IndicatorViewPager indicatorViewPager;
	private ViewPager viewPager;
	private LayoutInflater mInflater;
	private View mView; // 解析布局

	private List<String> tabs = new ArrayList<String>();
	private List<Fragment> fragments = new ArrayList<Fragment>();
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.article_layout, container, false);
		initViews();
		return mView;
	}

	private void initViews() {
		viewPager = (ViewPager) mView.findViewById(R.id.article_viewPager);
		ScrollIndicatorView indicator = (ScrollIndicatorView) mView.findViewById(R.id.article_tab_indicator); //设置滚动条
		indicator.setScrollBar(new ColorBar(getActivity(), getResources().getColor(R.color.tab_top_text_select), 7)); 
		
		//设置滚动指示条字体颜色改变
		int selectColor = R.color.tab_top_text_select;
		int unselectColor = R.color.tab_top_text_unselect;
		indicator.setOnTransitionListener(new OnTransitionTextListener().setColorId(getActivity(),selectColor, unselectColor));
		viewPager.setOffscreenPageLimit(20);
		mInflater = LayoutInflater.from(getActivity());
		
		indicatorViewPager = new IndicatorViewPager(indicator, viewPager);
		
		String[] tabsArray={"最新","快报","视频","新闻","评测","导购","行情","用车","技术","文化","改装","游记","原创视频","说客"};
		tabs.addAll(Arrays.asList(tabsArray));
		
		fragments.add(new ArticleFragmentNewest());
		for (int i = 0; i < 13; i++) {
			fragments.add(new TestFragment());
		}
		
		ArticleMainAdapter adapter = new ArticleMainAdapter(getChildFragmentManager());
		adapter.initAdapter(tabs, fragments);
		indicatorViewPager.setAdapter(adapter);
		
	}
}
